/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package edu.pku.sei.ocl.cst.impl;

import edu.pku.sei.ocl.cst.CSTPackage;
import edu.pku.sei.ocl.cst.OperationCS;
import edu.pku.sei.ocl.cst.OperationContextDeclCS;
import edu.pku.sei.ocl.cst.PrePostOrBodyDeclCS;
import edu.pku.sei.ocl.evaluation.Context;
import edu.pku.sei.ocl.visitor.AbstractOCLVisitor;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Operation Context Decl CS</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.OperationContextDeclCSImpl#getOperationCS <em>Operation CS</em>}</li>
 *   <li>{@link edu.pku.sei.ocl.cst.impl.OperationContextDeclCSImpl#getPrePostOrBodyDecls <em>Pre Post Or Body Decls</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class OperationContextDeclCSImpl extends ContextDeclCSImpl implements
		OperationContextDeclCS {
	/**
	 * The cached value of the '{@link #getOperationCS() <em>Operation CS</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOperationCS()
	 * @generated
	 * @ordered
	 */
	protected OperationCS operationCS;

	/**
	 * The cached value of the '{@link #getPrePostOrBodyDecls() <em>Pre Post Or Body Decls</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrePostOrBodyDecls()
	 * @generated
	 * @ordered
	 */
	protected EList<PrePostOrBodyDeclCS> prePostOrBodyDecls;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected OperationContextDeclCSImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return CSTPackage.Literals.OPERATION_CONTEXT_DECL_CS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public OperationCS getOperationCS() {
		return operationCS;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetOperationCS(OperationCS newOperationCS,
			NotificationChain msgs) {
		OperationCS oldOperationCS = operationCS;
		operationCS = newOperationCS;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this,
					Notification.SET,
					CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS,
					oldOperationCS, newOperationCS);
			if (msgs == null)
				msgs = notification;
			else
				msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOperationCS(OperationCS newOperationCS) {
		if (newOperationCS != operationCS) {
			NotificationChain msgs = null;
			if (operationCS != null)
				msgs = ((InternalEObject) operationCS)
						.eInverseRemove(
								this,
								EOPPOSITE_FEATURE_BASE
										- CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS,
								null, msgs);
			if (newOperationCS != null)
				msgs = ((InternalEObject) newOperationCS)
						.eInverseAdd(
								this,
								EOPPOSITE_FEATURE_BASE
										- CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS,
								null, msgs);
			msgs = basicSetOperationCS(newOperationCS, msgs);
			if (msgs != null)
				msgs.dispatch();
		} else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET,
					CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS,
					newOperationCS, newOperationCS));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<PrePostOrBodyDeclCS> getPrePostOrBodyDecls() {
		if (prePostOrBodyDecls == null) {
			prePostOrBodyDecls = new EObjectContainmentEList<PrePostOrBodyDeclCS>(
					PrePostOrBodyDeclCS.class,
					this,
					CSTPackage.OPERATION_CONTEXT_DECL_CS__PRE_POST_OR_BODY_DECLS);
		}
		return prePostOrBodyDecls;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd,
			int featureID, NotificationChain msgs) {
		switch (featureID) {
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS:
			return basicSetOperationCS(null, msgs);
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__PRE_POST_OR_BODY_DECLS:
			return ((InternalEList<?>) getPrePostOrBodyDecls()).basicRemove(
					otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS:
			return getOperationCS();
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__PRE_POST_OR_BODY_DECLS:
			return getPrePostOrBodyDecls();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS:
			setOperationCS((OperationCS) newValue);
			return;
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__PRE_POST_OR_BODY_DECLS:
			getPrePostOrBodyDecls().clear();
			getPrePostOrBodyDecls().addAll(
					(Collection<? extends PrePostOrBodyDeclCS>) newValue);
			return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS:
			setOperationCS((OperationCS) null);
			return;
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__PRE_POST_OR_BODY_DECLS:
			getPrePostOrBodyDecls().clear();
			return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__OPERATION_CS:
			return operationCS != null;
		case CSTPackage.OPERATION_CONTEXT_DECL_CS__PRE_POST_OR_BODY_DECLS:
			return prePostOrBodyDecls != null && !prePostOrBodyDecls.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	@Override
	public Object accept(AbstractOCLVisitor v, Context env, Object... argv) {
		if (argv == null || argv.length == 0) {
			return v.visitOperationContextDeclCS(this, env);
		} else {
			return v.visitOperationContextDeclCS(this, env, argv);
		}
	}
} //OperationContextDeclCSImpl
